package org.zoomdev.zoom.dao.struct;

/**
 * 字段结构
 */
public class ColumnMeta {

    protected final int type;

    protected final Class columnType;
    protected final String name;
    private final TableMeta tableMeta;
    protected String table;
    private String defaultValue;
    private boolean nullable;
    private int maxLength;
    private String rawType;
    private KeyType keyType;
    private boolean autoIncrement;
    private String comment;

    public ColumnMeta(TableMeta tableMeta, int type, Class columnType, String table, String name) {
        this.tableMeta = tableMeta;
        this.type = type;
        this.columnType = columnType;
        this.table = table;
        this.name = name;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public boolean isNullable() {
        return nullable;
    }

    public void setNullable(boolean nullable) {
        this.nullable = nullable;
    }

    public int getMaxLength() {
        return maxLength;
    }

    public void setMaxLength(int maxLength) {
        this.maxLength = maxLength;
    }

    public String getRawType() {
        return rawType;
    }

    public void setRawType(String rawType) {
        this.rawType = rawType;
    }

    public KeyType getKeyType() {
        return keyType;
    }

    public void setKeyType(KeyType keyType) {
        this.keyType = keyType;
    }

    public boolean isAutoIncrement() {
        return autoIncrement;
    }

    public void setAutoIncrement(boolean autoIncrement) {
        this.autoIncrement = autoIncrement;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getName() {
        return name;
    }

    public TableMeta getTableMeta() {
        return tableMeta;
    }

    public Class<?> getColumnType() {
        return columnType;
    }


    public enum KeyType {
        /**
         * 主键
         */
        PRIMARY,

        /**
         * 唯一键（唯一约束）
         */
        UNIQUE,

        /**
         * 一般索引（不含有唯一索引）
         */
        INDEX
    }
}
